<!DOCTYPE html>
<html lang="en" >
<head >
    <meta charset="utf-8" >
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" >
    <meta name="description" content="" >
    <meta name="author" content="ThemeBucket" >
    <link rel="shortcut icon" href="#" type="image/png" >

    <title >Dynamic Table</title >
    <link href="/public/js/iCheck/skins/minimal/blue.css" rel="stylesheet">
    <link href="/public/js/advanced-datatable/css/demo_page.css" rel="stylesheet" />
    <link href="/public/js/advanced-datatable/css/demo_table.css" rel="stylesheet" />
    <link rel="stylesheet" href="/public/js/data-tables/DT_bootstrap.css" />
    <?php $this->load->view('library/header'); ?>
</head >
<body class="sticky-header" >
<section >
    <?php $this->load->view('library/left'); ?>
    <div class="main-content" >
        <?php $this->load->view('library/top'); ?>
        <div class="page-heading" >
            <h3 >
                产品列表 </h3 >
            <ul class="breadcrumb" >
                <li >
                    <a href="#" >Dashboard</a >
                </li >
                <li >
                    <a href="#" >Data Tables</a >
                </li >
                <li class="active" > Dynamic Table</li >
            </ul >
        </div >
        <div class="wrapper" >
            <div class="row" >
                <div class="col-sm-12" >
                    <?php $this->load->view('library/search');?>
                    <section class="panel" >
                        <div class="panel-body" >
                            <div class="adv-table" >
                                <table class="display table table-bordered table-striped" id="dynamic-table" >
                                    <thead >
                                    <tr >
                                        <th width="6%" >编号</th >
                                        <th width="10%" >图片</th >
                                        <th width="20%" >商品名称</th >
                                        <th width="10%" class="hidden-phone" >货号</th >
                                        <th width="9%" class="hidden-phone" >供货商</th >
                                        <th width="10%" class="hidden-phone" >价格</th >
                                        <th width="10%" class="hidden-phone" >添加时间</th >
                                        <th width="5%" class="hidden-phone" >操作</th >
                                    </tr >
                                    </thead >
                                    <tbody >
                                    <?php foreach ($baby_goods as $item): ?>
                                        <tr class="gradeX" >
                                            <td ><label ><?php echo $item['id']; ?></label ></td >
                                            <td ><a href="#myModal_img" data-toggle="modal"><img  goods_id="<?php echo $item['goods_id']; ?>" style="width: 100px;" src="<?php echo $item['baby_goods_img']; ?>" /></a></td >
                                            <td >
                                                <?php echo $item['baby_goods_name']; ?>
                                                <br /> 
                                                产品链接: <a style="display: block; width: 300px;" target="_blank" class="proce-goods" href="<?php echo $item['baby_goods_link']; ?>" ><?php echo $item['baby_goods_link']; ?></a >
                                            </td >

                                            <td class="center hidden-phone" ><span class="keydiv"><?php echo $item['baby_goods_sn']; ?></span> 
                                                <?php foreach ($item['shopify'] as $v): ?>
                                                    <span class="btn btn-default btn-xs delete_goods_web" goods_id="<?php echo $item['id'];?>" web_name="<?php echo $v['web_name'];?>" web_id="<?php echo $v['web_id'];?>"><?php echo $v['web_name'];?>:<?php echo $v['time'];?></span>
                                                <?php endforeach; ?>
                                            </td >
                                            <td class="hidden-phone" ><?php echo $item['baby_gooda_supplier']; ?></td >
                                            <td class="center hidden-phone" >
                                                <p>进价：<?php echo $item['baby_goods_enter_price']?></p>
                                                <p>售价：<?php echo $item['baby_goods_price']?></p>
                                            <td class="center hidden-phone" ><?php echo date('Y-m-d', $item['baby_add_time']); ?></td >
                                            

                                            <td class="hidden-phone" >
                                                <a class="btn btn-xs btn-info" href="<?php echo base_url('Baby/baby_goods_save/baby_id/' . $item['id']); ?>" >编辑</a >
                                                <a class="btn btn-xs btn-info import-ajax" data-baby_goods_id="<?php echo $item['id'];?>" data-sn="<?php echo $item['baby_goods_sn']; ?>" >上传</a >
                                                <?php if($item['baby_e_update']) { ?>
                                                <a style="background: red;" class="btn btn-xs btn-info goods_e_sku" href="#myModal" data-toggle="modal" data-goods_id="<?php echo $item['id']; ?>" >上传E仓</a >
                                                <?php } ?>
                                                <a style="background: red;" class="btn btn-xs btn-info goods_e_sku_attr" data-goods_id="<?php echo $item['id']; ?>" >更新E仓规格图片</a >
                                            </td >
                                        </tr >
                                    <?php endforeach; ?>
                                    </tbody >
                                </table >
                            </div >
                            <div class="row-fluid" >
                                <div class="span6" >
                                    <div class="dataTables_paginate paging_bootstrap pagination" >
                                        <ul >
                                            <?php echo $pages; ?>
                                        </ul >
                                    </div >
                                </div >
                            </div >
                        </div >
                    </section >
                </div >
            </div >
        </div >
        <footer >
            2014 &copy; AdminEx by
        </footer >
    </div >
    <!--审核弹窗-->
        <div
                class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
                aria-hidden="true" >
            <div class="modal-dialog" >
                <div class="modal-content" >
                    <div class="modal-header" ><h4 class="modal-title" >审核产品sku</h4 ></div >
                    <div class="modal-body row" >
                        <table border="1px" >
                            <tr >
                                <td style="width: 100px;" >图片</td >
                                <td style="width: 200px;" >头</td >
                                <td style="width: 200px;" >尺码</td >
                                <td style="width: 200px;" >SKU</td >
                            </tr >
                        </table >
                        <table class="aaa" >

                        </table >

                        <div class="col-md-7" >

                            <div class="pull-right" >
                                <button class="btn btn-success btn-sm goods_sku_examine" type="button" >审核</button >
                            </div >
                        </div >
                    </div >
                </div >
            </div >
        </div >
</section >
<?php $this->load->view('library/footer'); ?>
<script src="/public/js/iCheck/jquery.icheck.js"></script>
<script src="/public/js/icheck-init.js"></script>
<script src="/public/js/scripts.js" ></script >
<script id="select-website" type="text/x-jquery-tmpl">
  <select size="2" id="choose" style="width: 90%;font-size: 16px;height:150px" multiple>
    <?php foreach($siteweb as $key => $value ):?>
    <option value="<?php echo $key; ?>"><?php echo $value; ?></option>
    <?php endforeach; ?>
  </select>
  <p style="padding: 10px;color: #f00;font-size:14px;text-align: left">请按住ctrl多选<p>
</script>
<script>
        $ ('.goods_e_sku').click (function () {

        var goods_id = $ (this).data ('goods_id');
        $ ('.goods_sku_examine').attr ('goods_id', goods_id);
        $.ajax ({
            type: 'post',
            url: "<?php echo base_url('Baby/baby_ww_goods_e_sku');?>",
            dataType: 'json',
            data: {
                goods_id: goods_id,
            },
            success: function (msg) {
                var aa = '';
                $.each (msg, function (k, v) {
                    aa += '<tr style="border-style:dashed;border-width:2px;">';
                    aa += '<td style="width: 100px;"><img style="width:50px;height:50px;" src="' + v.baby_goods_img + '"/></td>';
                    aa += '<td style="width: 200px;">' + v.baby_sku_head + '</td>';
                    aa += '<td style="width: 200px;">' + v.baby_sku_size + '</td>';
                    aa += '<td style="width: 200px;">' + v.baby_goods_sku + '</td>';
                    aa += '</tr>';
                })
                $ ('.aaa').html (aa);
            }
        })
    })

    $ ('.goods_sku_examine').click (function () {
        $ (this).attr ('disabled', true);
        var goods_id = $ (this).attr ('goods_id');
        var url = "<?php echo base_url('Baby/pets_ww_goods_sku_examine'); ?>";
        swal ({
            title: '提交sku',
            allowOutsideClick: false,
            confirmButtonText: 'Submit',

            preConfirm: function preConfirm(value) {
                swal ({
                    imageUrl: '/public/images/Forrest.gif',
                    title: '稍等...',
                    allowOutsideClick: false,
                    showConfirmButton: false
                });
                return $.post (url, {goods_id: goods_id}, function (data) {
                    return data;
                }, 'json');
            }
        }).then (function (result) {
            if (result.value) {
                var data = result.value;
                swal ({
                    type: data.status,
                    title: data.info
                }).then (function (isConfirm) {
                    location.reload ();
                });
            }
        });
    })

    $ (".import-ajax").on ("click", function () {
        var url = "<?php echo base_url('Baby/baby_goods_shopify'); ?>";
        var goods_sn = $ (this).attr ('data-sn');
        var baby_goods_id = $(this).data('baby_goods_id');
        var chooseValue = [];
        swal ({
            title: goods_sn,
            input: 'input',
            html: $('#select-website').html(),
            inputOptions: <?php echo $siteweb_json; ?>,
            showCancelButton: true,
            allowOutsideClick: false,
            confirmButtonText: 'Submit',
            inputPlaceholder: '请选择网站',
            customClass: "sweetAlert",
            inputValidator: function () {
                chooseValue = $('#choose').val()
                if (!($('#choose').val().length)) {
                    return '未选择任何网站!';
                }
            },
            preConfirm: function preConfirm() {
                swal ({
                    imageUrl: '/public/images/Forrest.gif',
                    title: '稍等...',
                    allowOutsideClick: false,
                    showConfirmButton: false
                });

                var data = {};
                $.each(chooseValue,function(index,value){
                    data[index] = value
                });

                return $.post (url, {web_id : data,baby_goods_id : baby_goods_id}, function (data) {
                    return data;
                }, 'json');
            }
        }).then (function (result) {
            if (result.value) {
                var data = result.value;
                swal ({
                    type: data.status,
                    title: data.info
                }).then (function (isConfirm) {
                    location.reload ();
                });
            }
        });

        return false;
    });
    //e仓商品规格图片更新
    $ ('.goods_e_sku_attr').click (function () {
        var _this = $ (this);
        swal ({
            title: 'e仓规格图片更新',
            showCancelButton: true,
            preConfirm: function preConfirm(value) {
                var goods_id = _this.data ('goods_id');
                swal ({
                    imageUrl: '/public/images/Forrest.gif',
                    title: '稍等...',
                    allowOutsideClick: false,
                    showConfirmButton: false
                });
                return $.post ("<?php echo base_url('Baby/syncProduct_ww_attr_img');?>", {goods_id: goods_id}, function (data) {
                    return data;
                }, 'json');
            }
        }).then (function (result) {
            if (result.value) {
                var data = result.value;
                swal ({
                    type: data.status,
                    title: data.info
                }).then (function (isConfirm) {
                    location.reload ();
                });
            }
        });
    });
</script>
</body >
</html >
